<?php

class Create extends Controller {

	function Create() {
		parent::Controller();
	}

	function index() {
		if( isset($_POST['submit']) ) {
			if( trim($this->input->post('user')) == '' ) {
				$this->error = 'Please enter an username';
			} else if( trim($this->input->post('password')) == '' ) {
				$this->error = 'Enter a password';
			} else if( $this->input->post('password') != $this->input->post('password_confirm') ) {
				$this->error = 'Passwords do not match';
			} else if( strstr('@', $this->input->post('email') ) ) {
				$this->error = 'Invalid email address';
			} else {
				$this->Accounts->create( $this->input->post('department_id'), 
					$this->input->post('user'),
					$this->input->post('password'),
					$this->input->post('first_name'),
					$this->input->post('last_name'),
					$this->input->post('email') );
				redirect( 'account/view', 'location' );
			}
		}
		$this->load->view('account/create');
	}

}

?>
